<?php namespace App\Http\Controllers\Merchant;

use App\Http\Requests;
use App\Http\Controllers\Controller;

class MerchantController extends Controller {

    public function getIndex()
    {
        $allMenu = [
            'merchant-system' => [
                'name' => '常规',
                'items' => [
                    ['name' => '重置密码', 'node' => 'merchant-sys-repass'],
                ],
            ],

            'merchant-product' => [
                'name'  => "信息",
                'items' => [
                    ["name" => "信息管理", 'node' => 'merchant-product'],
                ]
            ],
        ];

        $menu = [];
        foreach($allMenu as $k => $v) {
            $sublink = [];
            foreach ($v['items'] as $node) {
                $sublink[] = $node;
            }

            if (count($sublink)) {
                $menu[$k]['name']   = $v['name'];
                $menu[$k]['id']     = $k;
                $menu[$k]['parent'] = 'root';

                $items = [];
                foreach($sublink as $s) {
                    $items[$s['node']] = [
                        'id'        => $s['node'],
                        'name'      => $s['name'],
                        'parent'    => $k,
                        'url'       => url(str_replace('-', '/', $s['node'])),
                    ];
                }

                $menu[$k]['items'] = $items;
            }
        }

        return view('merchant.index', ['menu' => json_encode($menu, true)]);
    }

}
